<?php
session_start();
	require_once("PHP/db_connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="./js/jquery.corner.js"></script>
<script type="text/javascript">
	$(document).ready(
		function() {
			$("#reflesh").click(function(){
				$.ajax({
					type: "GET",
					url: "login.php",
					timeout : 3000,
					dataType: "json",
					error:function(){
					},
					success:function(result){
						$("#men_women > img").attr({
							src: "http://chart.apis.google.com/chart?chs=460x230&chd=t:"+result.men+","+result.women+"&cht=p&chl=男|女&chco=0000FF,FF0000&chtt=応募者の男女比&chdl=男++++"+result.men+"人|女++++"+result.women+"人&chco=0000FF,FF0000"
						});
					}
				})
			});
			$("#volunteer").click(function () {
				$("#target").attr({
					action: "./PHP/serch_function/index_search.php?target=volunteer"
				});
			});

			$("#thread").click(function () {
				$("#target").attr({
					action: "./PHP/serch_function/index_search.php?target=thread"
				});
			});

			$('.box').corner();
			$('.box2').corner();
			$('.box3').corner();
			$('.box4').corner();
			<?php
				echo array_key_exists("error",$_SESSION)?"login_error('".htmlspecialchars($_SESSION['error'],ENT_QUOTES,"UTF-8")."');":"";
				unset($_SESSION["error"]);
			?>
	});
	function login_error(error){
		alert(error);
	}
</script>
<link rel="stylesheet"  href="./css/top_css.css" type="text/css" />
<title>ボランティア掲示システム</title>
</head>
    <body>
	<div id="container">
		<div id="header" class="box4">
			<div id="logo">
			</div>
			<div id="header_box" >
				<div id="title">
					ボランティア掲示システム
				</div>
				<div id="search_box">
					<a href="#" id="volunteer">ボランティア</a>｜<a href="#" id="thread">掲示板</a>
					<form method="post" action="./PHP/serch_function/index_search.php?target=default" id="target">
						<input type="text" name="search_word">
						<input type="submit" value="検索する">
					</form>
				</div>
			</div>
		</div>
		<div id="leftnavi" class="box2">
			<h3>カテゴリ別検索</h3>
				<ul class="menu_margin2">
					<?php require_once("PHP/treemenu.php") ?>
				</ul>
			<h3>地域別検索</h3>
				<ul class="menu_margin2">

					<?php require_once("PHP/treemenu2.php") ?>

				</ul>
		</div>
		<div id="rightnavi" class="box">
		<h3>ログインフォーム</h3>
		<?php if(empty($_SESSION["user_name"])&&empty($_SESSION["user_id"])){?>
			<form method="post" action="./PHP/user_function/UserLogin.php">
				ID：　　<input type="text" name="id" size="10"><br />
				PASS：<input type="password" name="pass" size="10"><br />
				<input style="margin:10px 0 0 39px;" type="image" src="./img/login.png" alt="送信ボタン" name="submit" align="middle">
			</form>
			<form action="PHP/user_funtion/User_create.php"><input type="image" src="./img/newuser.png"></form>
			<a href="./PHP/User_create.php">新規会員登録</a>
		<?php }else{?>
				<p>ようこそ<?php echo $_SESSION['nick_name']?>さん！</p>
				<p><a href="./PHP/user_function/user_infomation.php">会員情報表示</a></p>
				<p><a href="./PHP/user_function/user_update.php">会員情報変更</a></p>
				<p><a href="./PHP/user_function/user_display_application.php">申請中ボランティア</a></p>
				<p><a href="./PHP/user_function/user_display_volunteer.php">提供中ボランティア</a></p>
				<p><a href="./PHP/volunteer_Information_insert.php">ボランティア作成</a></p>
				<p><a href="./PHP/user_function/logout.php">ログアウト</a></p>
				<br />
		<?php }?>
		<h3>掲示板</h3>
				<ul class="menu_margin">
	<div id="thread_title">
<?php
	$db = DB::connect($dsn);	//DBへ接続する

	if (PEAR::isError($db)) {	//DBの接続に失敗すればここでエラー文を出力
	    die($db->getMessage());
	}

	//スレッド項目取得
	$sql = "SELECT thread_id,thread_name from thread order by thread_date DESC limit 0,5";
	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//スレッド表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
	  echo "<li><a href='./PHP/response.php?thread_id=".$data['thread_id']."'>";
	  echo mb_strlen($data['thread_name'])>=9?mb_substr($data['thread_name'],0,9)."...":$data['thread_name'];
	  echo "</a></li>";
	}
?>
				</ul>
		<div id="more"><a href="./PHP/thread.php">もっと見る...</a></div>
	</div>
			<div id="main"  class="box3">

    </body>
</html>